<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>桶 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/_buckets.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/_buckets.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_buckets.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/_buckets.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="aggregations.html">聚合</a></span>
»
<span class="breadcrumb-link"><a href="aggs-high-level.html">高阶概念</a></span>
»
<span class="breadcrumb-node">桶</span>
</div>
<div class="navheader">
<span class="prev">
<a href="aggs-high-level.html">« 高阶概念</a>
</span>
<span class="next">
<a href="_metrics.html">指标 »</a>
</span>
</div>
<div class="section pagebreak-before">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_buckets"></a>桶 (Buckets)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/301_Aggregation_Overview.asciidoc">edit</a>
</h2>
</div></div></div>
<p><em>桶 (bucket)</em>, 简单来说就是满足某个特定条件的文档的集合：</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
一个雇员属于 <em>男性</em> 桶或者 <em>女性</em> 桶
</li>
<li class="listitem">
奥尔巴尼属于 <em>纽约</em> 桶
</li>
<li class="listitem">
日期2014-10-28属于 <em>十月</em> 桶
</li>
</ul>
</div>
<p>当聚合开始被执行，每个文档里面的值通过计算来决定符合哪个桶的条件。如果匹配到，文档将放入相应的桶并接着进行聚合操作。</p>
<p>桶也可以被嵌套在其他桶里面，提供层次化的或者有条件的划分方案。例如，辛辛那提会被放入俄亥俄州这个桶，而 <em>整个</em> 俄亥俄州桶会被放入美国这个桶。</p>
<p>Elasticsearch 有很多种类型的桶，能让你通过很多种方式来划分文档（时间、最受欢迎的词、年龄区间、地理位置等等）。其实根本上都是通过同样的原理进行操作：基于条件来划分文档。</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="aggs-high-level.html">« 高阶概念</a>
</span>
<span class="next">
<a href="_metrics.html">指标 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>